<template>
  <el-dialog
    :title="!dataForm.id ? '审核' : '审核'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form :model="dataForm" ref="dataForm" @keyup.enter.native="dataFormSubmit()">
      <el-form-item label="状态：" prop="status">
        <el-radio-group v-model="dataForm.status">
          <el-radio :label="1">审核通过</el-radio>
          <el-radio :label="2">审核不通过</el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" :loading="loading">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      visible: false,
      loading: false,
      dataForm: {
        id: '',
        status: 1
      }
    }
  },
  methods: {
    init(id, checkStatus) {
      this.dataForm.id = id || 0
      this.dataForm.status = checkStatus
      this.visible = true
      this.$nextTick(() => {
        this.$refs['dataForm'].resetFields()
      })
    },
    dataFormSubmit() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.loading = true
          this.$http({
            url: this.$http.adornUrl(`/train/traindata/checkTrainComment`),
            method: 'post',
            data: {
              id: this.dataForm.id,
              status: this.dataForm.status
            }
          }).then(data => {
            if (data && data.code === 200) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500
              })
              this.$emit('refreshDataList')
              this.visible = false
            } else {
              this.$message.error(data.msg)
            }
            this.loading = false
          })
        }
      })
    }
  }
}
</script>

<style scoped>
</style>
